package zhenbang
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.text.TextField;
	public class SignPage extends Sprite
	{
		private static var _main:SignPage = null;
		public static function get main():SignPage
		{
			if(_main==null)
				_main = new SignPage();
			return _main;
		}
		public function SignPage()
		{
			_main = this;
			addChild(new Bitmap(test.main.bg.bitmapData));
			//nextBtn = new BtnBase(toNext,test.newBtn("下一步"));
			//nextBtn = new BtnBase(toNext,new Assets.next_png);
			nextBtn = new BtnBase(toNext,new Assets.upload_png);
			//resetBtn = new BtnBase(toClear,test.newBtn("重签"));
			resetBtn = new BtnBase(toClear,new Assets.resign_png);
			//backBtn = new BtnBase(back,test.newBtn("返回"));
			backBtn = new BtnBase(back,new Assets.back_png);
			//nextBtn.width = resetBtn.width = backBtn.width = 300;
			//nextBtn.height = resetBtn.height = backBtn.height = 100;
			addChild(nextBtn);
			addChild(resetBtn);
			addChild(backBtn);

			nextBtn.y = resetBtn.y = 870;
			nextBtn.x = width*6.1/19 - nextBtn.width/2;
			resetBtn.x = width*13.5/19 - resetBtn.width/2;

			drawBoard = new DrawBoard();
			drawBoard.x = 870; 
			drawBoard.y = 170; 

			drawBoardBg = new Assets.signBoad_png();
			drawBoardBg.x = drawBoard.x; 
			drawBoardBg.y = drawBoard.y; 
			drawBoardBg.width = drawBoard.width;
			drawBoardBg.height = drawBoard.height;
			addChild(drawBoardBg);

			addChild(drawBoard);

			width = test.stageW;
			height = test.stageH;
		}

		private var nextBtn:BtnBase;
		private var resetBtn:BtnBase;
		private var backBtn:BtnBase;

		public static var drawBoard:DrawBoard;
		private var drawBoardBg:Bitmap;

		private function toClear():void
		{
			logs.adds("重签");
			drawBoard.clear();
		}
		private function toNext():void
		{
			if (!drawBoard.hasDrawed)
			{
				Toast.show("您还没有签名");
				return;
			}
			//logs.adds("下一步");
			UploadPage.show();
		}

		private static var photo:Bitmap;
		private static function delBmp(bmp:Bitmap):void
		{
			if(bmp)
			{
				if(bmp.parent)
					bmp.parent.removeChild(bmp);
				bmp.bitmapData.dispose();
			}
		}

		private static var indexTxt:TextField;
		public static function show():void
		{
			main.visible = true;
			test.main.addChild(main);
			delBmp(photo);
			photo = new Bitmap(CameraPage.photoBmp.bitmapData);
			main.addChild(photo);
			photo.width = 400;
			photo.scaleY = photo.scaleX;
			photo.x = 330-photo.width/2;
			photo.y = 540 -photo.height/2;
			main.addChild(drawBoard);
			drawBoard.scaleY = drawBoard.scaleX = 1.0;
			drawBoard.x = 870; 
			drawBoard.y = 170; 
			drawBoard.clear();

			indexTxt = Datas.setIndexTxt(indexTxt);
			main.addChild(indexTxt);
		}
		public static function back():void
		{
			main.visible = false;
			FirstPage.show();
		}
	}
}
